

pdf("04_manuscript/figures/age_gender_gap_plot.pdf", width = 9,height = 4.5)
print(full_data %>% filter(not_panel == 1) %>% 
  mutate(age_cat = cut(age,
                       breaks = c(18,20,25,30,35,40,100),
                       include.lowest = TRUE)) %>% 
  filter(!is.na(age_cat)) %>% 
  group_by(age_cat) %>% 
  summarize(sfmv_w = mean(sfmv[woman == 1], na.rm = TRUE),
            sfmv_m = mean(sfmv[woman == 0], na.rm = TRUE),
            n_w = sum(woman,na.rm = TRUE), 
            n_m = sum(woman == 0,na.rm = TRUE), 
            gap = sfmv_w - sfmv_m) %>% 
  mutate(
            y_pos = abs(gap)/2 + pmin(sfmv_w,sfmv_m),
            gap_label = round(gap,2)*100,
            gap_label = ifelse(grepl("-",gap_label),gap_label,paste0("+",gap_label)),
            gap_label = paste0(gap_label, " pp.")) %>% 
  ggplot(., aes(x = age_cat)) +
  geom_segment(aes(x = age_cat, xend = age_cat, y = sfmv_w, yend = sfmv_m)) +
  geom_point(aes(y = sfmv_w, size = n_w), color = "steelblue2") +
  geom_text(aes(y = sfmv_w, label = "W"),size = 3, color = "steelblue4",nudge_x = 0) +
  geom_point(aes(y = sfmv_m, size = n_m), color = "seagreen2",fill = "white") +
  geom_text(aes(y = sfmv_m, label = "M"),size = 3, color = "seagreen4",nudge_x = 0) +
  scale_size_continuous("N") +
  scale_y_continuous(labels = scales::percent, 
                     name = "% who support mob violence",
                     limits = c(0,.15)) + 
  scale_x_discrete("Age group") +
  geom_text(aes(y = y_pos, label = gap_label), 
            nudge_x = .2) +
  theme_bw() )
dev.off()


